package com.example.controller;

import com.example.pojo.Doctor;
import com.example.pojo.DoctorQuery;
import com.example.pojo.Result;
import com.example.pojo.User;
import com.example.service.DoctorService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/doctor")
public class DoctorController {


    @Autowired
    private DoctorService doctorService;

    /**
     * 添加医师（2025.1.8检）
     * @param doctor
     * @return
     */
    @RequestMapping("/addDoctor")
    public Result addDoctorInformation(@RequestBody Doctor doctor){

        return  doctorService.addDoctorInformation(doctor);

    }

    /**
     * 医师查询、分页（2025.1.8检）
     * @param doctorQuery
     * @return
     */
    @RequestMapping("/getDoctorList")
    public Result getDoctorList(@RequestBody DoctorQuery doctorQuery){

        PageHelper.startPage(doctorQuery.getPageNum(),doctorQuery.getPageSize());

        System.err.println(doctorQuery);
        List<Doctor> list=doctorService.getUserList(doctorQuery);
        // System.err.println(list);

        PageInfo<Doctor> pageInfo=new PageInfo<>(list);

        Map<String,Object> resultMap=new HashMap<>();

        //当前页数据
        resultMap.put("list",pageInfo.getList());

        //数据总数
        resultMap.put("total",pageInfo.getTotal());

        return new Result(200,"数据加载成功",resultMap);

    }

    /**
     * 医师添加（2025.1.8检）
     * @param doctor
     * @return
     */
    @RequestMapping("/edit")
    public Result insertByAccount(@RequestBody Doctor doctor){

        return doctorService.insertByAccount(doctor);

    }

    /**
     * 医师单个删除（2025.1.8检）
     * @param map
     * @return
     */
    @RequestMapping("/delDoctotById")
    public Result delDoctorById(@RequestBody Map<String,Integer> map){

        int id =map.get("id");

        return doctorService.delDoctorById(id);
    }

    /**
     * 医师批量删除（2025.1.8修正）
     *
     * @param map
     * @return
     */
    @RequestMapping("/delBatch")
    public Result delBatch(@RequestBody Map<String,String> map){

        String ids = map.get("ids");

        return doctorService.delBatch(ids);
    }
}
